package com.gitee.neuray.security.generator.utils;

import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @author: zhhongyu
 * @description: enum工具类
 * @since: Create in 11:30 2020/2/19
 */
public class CodeEnumUtils {
    public static Map<String, Object> getAllEnum(Class claz) throws Exception {
        // 得到枚举类对象
        Class<Enum> clazz = (Class<Enum>) Class.forName(claz.getName());
        //获取所有枚举实例
        Enum[] enumConstants = clazz.getEnumConstants();
        //根据方法名获取方法
        Method getName = clazz.getMethod("getName");
        Method getIndex = clazz.getMethod("getIndex");
        Map<String, Object> map = new HashMap<String, Object>();
        for (Enum enum1 : enumConstants) {
            //执行枚举方法获得枚举实例对应的值
            map.put((String) getIndex.invoke(enum1),(String) getName.invoke(enum1) );
        }
        return map;
    }
}
